package com.msb.strategy.filter.impl;

import com.msb.common.enums.ExceptionEnums;
import com.msb.common.model.StandardSubmit;
import com.msb.strategy.filter.StrategyFilter;
import com.msb.strategy.util.ErrorSendMessage;
import com.msb.strategy.util.HutoolDFAUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: lmf
 * @Create: 2025/3/13 9:03
 * @module
 */
@Slf4j
@Service(value = "HutoolDirtyWord")
public class HutoolDirtyWordStrategyFilter implements StrategyFilter {
    @Resource
    private ErrorSendMessage errorSendMessage;

    @Override
    public void strategy(StandardSubmit submit) {

        String text = submit.getText();

        // 验证是否包含敏感词
        List<String> dirtyWords = HutoolDFAUtil.getDirtyWords(text);
        log.info("敏感词HutoolDirtyWord：{}", dirtyWords);

        if (dirtyWords.isEmpty()) {
            return;
        }
        submit.setErrorMessage(ExceptionEnums.ERROR_HAVE_DIRTY_WORD.getMsg() + dirtyWords);
        errorSendMessage.sendErrorMessage(submit, ExceptionEnums.ERROR_HAVE_DIRTY_WORD);
    }


}
